﻿namespace PMS.Client.FrmSyslog
{
    using DataGridViewPager;
    using PMS.BLL;
    using PMS.Client.Controls;
    using PMS.Client.Properties;
    using PMS.Common;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;
    using PMS.Model;

    public class FrmList : Form
    {
        private ToolStripButton btnAdd;
        private ToolStripButton btnDelete;
        private ToolStripButton btnUpdate;
        private IContainer components = null;
        private UCDataGridView dataGridView1;
        private List<Syslog> list = null;
        private DataGridViewTextBoxColumn LogClient;
        private DataGridViewTextBoxColumn LogContent;
        private DataGridViewTextBoxColumn LogDate;
        private DataGridViewTextBoxColumn LogID;
        private DataGridViewTextBoxColumn LogIP;
        private DataGridViewTextBoxColumn LogType;
        private DataGridViewTextBoxColumn LogUser;
        private Pager pager1;
        private Panel panel1;
        private ToolStrip toolStrip1;

        public FrmList()
        {
            this.InitializeComponent();
            this.dataGridView1.AutoGenerateColumns = false;
            if (PMS.Common.Keys.Admin.LoginName == "admin")
            {
                this.btnDelete.Enabled = true;
            }
            this.DgvBind();
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (this.dataGridView1.SelectedRows.Count > 0)
            {
                new SyslogBLL().Delete(int.Parse(this.dataGridView1.SelectedRows[0].Cells[""].Value.ToString()));
                this.DgvBind();
            }
            else
            {
                MessageBox.Show("请选择一条记录！");
            }
        }

        private int DgvBind()
        {
            int totalCount = 0;
            this.list = new SyslogBLL().GetList(this.pager1.PageCurrent, this.pager1.PageSize, out totalCount);
            this.pager1.NMax = totalCount;
            this.pager1.Bind();
            this.dataGridView1.DataSource = this.list;
            return totalCount;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            ComponentResourceManager manager = new ComponentResourceManager(typeof(FrmList));
            DataGridViewCellStyle style = new DataGridViewCellStyle();
            DataGridViewCellStyle style2 = new DataGridViewCellStyle();
            DataGridViewCellStyle style3 = new DataGridViewCellStyle();
            this.toolStrip1 = new ToolStrip();
            this.btnAdd = new ToolStripButton();
            this.btnUpdate = new ToolStripButton();
            this.btnDelete = new ToolStripButton();
            this.panel1 = new Panel();
            this.pager1 = new Pager();
            this.dataGridView1 = new UCDataGridView(this.components);
            this.LogID = new DataGridViewTextBoxColumn();
            this.LogDate = new DataGridViewTextBoxColumn();
            this.LogType = new DataGridViewTextBoxColumn();
            this.LogUser = new DataGridViewTextBoxColumn();
            this.LogContent = new DataGridViewTextBoxColumn();
            this.LogIP = new DataGridViewTextBoxColumn();
            this.LogClient = new DataGridViewTextBoxColumn();
            this.toolStrip1.SuspendLayout();
            this.panel1.SuspendLayout();
            ((ISupportInitialize) this.dataGridView1).BeginInit();
            base.SuspendLayout();
            this.toolStrip1.Items.AddRange(new ToolStripItem[] { this.btnAdd, this.btnUpdate, this.btnDelete });
            this.toolStrip1.Location = new Point(0, 0);
            this.toolStrip1.Name = "toolStrip1";
            this.toolStrip1.RenderMode = ToolStripRenderMode.System;
            this.toolStrip1.Size = new Size(0x365, 0x36);
            this.toolStrip1.TabIndex = 3;
            this.toolStrip1.Text = "toolStrip1";
            this.btnAdd.Enabled = false;
            this.btnAdd.Image = Resources.Icons_add;
            this.btnAdd.ImageScaling = ToolStripItemImageScaling.None;
            this.btnAdd.ImageTransparentColor = Color.Magenta;
            this.btnAdd.Name = "btnAdd";
            this.btnAdd.Size = new Size(0x24, 0x33);
            this.btnAdd.Text = "增加";
            this.btnAdd.TextImageRelation = TextImageRelation.ImageAboveText;
            this.btnUpdate.Enabled = false;
            this.btnUpdate.Image = Resources.Icons_update;
            this.btnUpdate.ImageScaling = ToolStripItemImageScaling.None;
            this.btnUpdate.ImageTransparentColor = Color.Magenta;
            this.btnUpdate.Name = "btnUpdate";
            this.btnUpdate.Size = new Size(0x24, 0x33);
            this.btnUpdate.Text = "修改";
            this.btnUpdate.TextImageRelation = TextImageRelation.ImageAboveText;
            this.btnDelete.Enabled = false;
            this.btnDelete.Image = (Image) manager.GetObject("btnDelete.Image");
            this.btnDelete.ImageScaling = ToolStripItemImageScaling.None;
            this.btnDelete.ImageTransparentColor = Color.Magenta;
            this.btnDelete.Name = "btnDelete";
            this.btnDelete.Size = new Size(0x24, 0x33);
            this.btnDelete.Text = "删除";
            this.btnDelete.TextImageRelation = TextImageRelation.ImageAboveText;
            this.btnDelete.Click += new EventHandler(this.btnDelete_Click);
            this.panel1.Controls.Add(this.pager1);
            this.panel1.Dock = DockStyle.Bottom;
            this.panel1.Location = new Point(0, 0x18b);
            this.panel1.Name = "panel1";
            this.panel1.Size = new Size(0x365, 0x26);
            this.panel1.TabIndex = 6;
            this.pager1.Dock = DockStyle.Fill;
            this.pager1.Location = new Point(0, 0);
            this.pager1.Name = "pager1";
            this.pager1.NMax = 0;
            this.pager1.PageCount = 0;
            this.pager1.PageCurrent = 1;
            this.pager1.PageSize = 50;
            this.pager1.Size = new Size(0x365, 0x26);
            this.pager1.TabIndex = 0;
            this.pager1.EventPaging += new EventPagingHandler(this.pager1_EventPaging);
            this.dataGridView1.AllowUserToAddRows = false;
            this.dataGridView1.AllowUserToDeleteRows = false;
            this.dataGridView1.AllowUserToResizeColumns = false;
            this.dataGridView1.AllowUserToResizeRows = false;
            this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            this.dataGridView1.BackgroundColor = Color.FromArgb(0xd9, 0xea, 0xf7);
            this.dataGridView1.BorderStyle = BorderStyle.None;
            this.dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
            this.dataGridView1.Columns.AddRange(new DataGridViewColumn[] { this.LogID, this.LogDate, this.LogType, this.LogUser, this.LogContent, this.LogIP, this.LogClient });
            style.Alignment = DataGridViewContentAlignment.MiddleLeft;
            style.BackColor = Color.FromArgb(0xd9, 0xea, 0xf7);
            style.Font = new Font("宋体", 9f, FontStyle.Regular, GraphicsUnit.Point, 0x86);
            style.ForeColor = SystemColors.ControlText;
            style.SelectionBackColor = SystemColors.Highlight;
            style.SelectionForeColor = SystemColors.ControlText;
            style.WrapMode = DataGridViewTriState.False;
            this.dataGridView1.DefaultCellStyle = style;
            this.dataGridView1.Dock = DockStyle.Fill;
            this.dataGridView1.EnableHeadersVisualStyles = false;
            this.dataGridView1.GridColor = Color.FromArgb(0xd0, 0xd7, 0xe5);
            this.dataGridView1.HighlightSelectedColumnHeaders = false;
            this.dataGridView1.Location = new Point(0, 0x36);
            this.dataGridView1.MultiSelect = false;
            this.dataGridView1.Name = "dataGridView1";
            this.dataGridView1.ReadOnly = true;
            this.dataGridView1.RowHeadersVisible = false;
            this.dataGridView1.RowTemplate.Height = 0x17;
            this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            this.dataGridView1.Size = new Size(0x365, 0x155);
            this.dataGridView1.TabIndex = 5;
            this.LogID.DataPropertyName = "LogID";
            style2.Alignment = DataGridViewContentAlignment.MiddleCenter;
            style2.BackColor = Color.FromArgb(0xd9, 0xea, 0xf7);
            this.LogID.DefaultCellStyle = style2;
            this.LogID.FillWeight = 5f;
            this.LogID.HeaderText = "ID";
            this.LogID.Name = "LogID";
            this.LogID.ReadOnly = true;
            this.LogDate.DataPropertyName = "LogDate";
            style3.BackColor = Color.FromArgb(0xd9, 0xea, 0xf7);
            this.LogDate.DefaultCellStyle = style3;
            this.LogDate.FillWeight = 13f;
            this.LogDate.HeaderText = "时间";
            this.LogDate.Name = "LogDate";
            this.LogDate.ReadOnly = true;
            this.LogType.DataPropertyName = "LogType";
            this.LogType.FillWeight = 12f;
            this.LogType.HeaderText = "日志类型";
            this.LogType.Name = "LogType";
            this.LogType.ReadOnly = true;
            this.LogUser.DataPropertyName = "LogUser";
            this.LogUser.FillWeight = 10f;
            this.LogUser.HeaderText = "操作用户";
            this.LogUser.Name = "LogUser";
            this.LogUser.ReadOnly = true;
            this.LogContent.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            this.LogContent.DataPropertyName = "LogContent";
            this.LogContent.FillWeight = 40f;
            this.LogContent.HeaderText = "日志内容";
            this.LogContent.Name = "LogContent";
            this.LogContent.ReadOnly = true;
            this.LogIP.DataPropertyName = "LogIP";
            this.LogIP.FillWeight = 10f;
            this.LogIP.HeaderText = "操作IP";
            this.LogIP.Name = "LogIP";
            this.LogIP.ReadOnly = true;
            this.LogClient.DataPropertyName = "LogClient";
            this.LogClient.FillWeight = 10f;
            this.LogClient.HeaderText = "LogClient";
            this.LogClient.Name = "LogClient";
            this.LogClient.ReadOnly = true;
            this.LogClient.Visible = false;
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x365, 0x1b1);
            base.Controls.Add(this.dataGridView1);
            base.Controls.Add(this.panel1);
            base.Controls.Add(this.toolStrip1);
            base.Icon = (Icon) manager.GetObject("$this.Icon");
            base.Name = "FrmList";
            base.StartPosition = FormStartPosition.CenterScreen;
            this.Text = "系统日志";
            this.toolStrip1.ResumeLayout(false);
            this.toolStrip1.PerformLayout();
            this.panel1.ResumeLayout(false);
            ((ISupportInitialize) this.dataGridView1).EndInit();
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        private int pager1_EventPaging()
        {
            return this.DgvBind();
        }
    }
}

